package com.szdtoo.response;

import java.util.Map;

/**
 * 返回信息类
 * @author SuXin
 */
public class Result {


    private Integer code = null;

    private String message = null;

    private Map<String,Object> objectMap = null;

    /**
     * 服务器时间
     */
    private Long timestamp = System.currentTimeMillis();

    public Result(){}

    public Result(int code, String message, Map<String, Object> objectMap) {
        this.code = code;
        this.message = message;
        this.objectMap = objectMap;
    }

    interface Code {
        int Ok = 400; //success
        int Error = 500; //failed
        int Redirect = 302; //重定向
        int Verify = 403; //权限禁止
    }

    public static Result success(String message,Map<String, Object> objectMap) {
        return new Result(Code.Ok, message, objectMap);
    }

    public static Result failed(String message) {
        return new Result(Code.Error, message, null);
    }

    public static Result redirect(String message) {
        return new Result(Code.Redirect,message,null);
    }

    public static Result verify(String message) {
        return new Result(Code.Verify,message,null);
    }

    public Result addObjectMap(Map<String,Object> objectMap) {
        this.objectMap = objectMap;
        return this;
    }
}
